package com.rubik.plugins.context.generate.file

import BY_VERSION
import com.ktnail.x.kdocToLines
import com.ktnail.x.updateFileKDoc
import com.ktnail.x.writeLines
import org.gradle.api.Project
import java.io.File

class ProjectSettingsFile(rootProject: Project, private val paths: MutableMap<String, Boolean>) {

    private val filePath = rootProject.rootDir.path + File.separator + "settings-rubik.gradle"

    fun generate() {
        cleanFile()
        val lines = mutableListOf<String>()
        lines.addAll(KDoc.settings())
        lines.addAll(paths.map { (path, enable) ->
            "${if (!enable) "// " else ""}include '$path'"
        })
        File(filePath).writeLines(lines)
    }

    private fun cleanFile() {
        File(filePath).delete()
    }

    object KDoc {
        fun settings() = updateFileKDoc("generated by Rubik Gradle Plugin (${BY_VERSION}).", null).kdocToLines()
    }
}


